Consider the following data definitions, taken from Module 01:
;; A Size is one of ;; -- "small" ;; -- "medium" ;; -- "large" ;; size-fn : Size -> ?? (define (size-fn s) (cond [(string=? s "small") ...] [(string=? s "medium") ...] [(string=? s "large") ...])) ;; A Year is a PosInt[1900,2020] ;; interp: the year. Must be between 1900 and 2020. ;; Year is Scalar data, so we don't need a template. ;; A Vineyard is ... /to be filled in/ (define-struct coffee (size type milk?)) (define-struct wine (vineyard year)) (define-struct tea (size type)) ;; A BarOrder is one of ;; -- (make-coffee Size String Boolean) ;; interp: ;; size is the size of cup desired ;; type is the origin of the coffee (as a string) ;; milk? tells whether milk is desired. ;; -- (make-wine Vineyard Year) ;; interp: ;; vineyard is the origin of the grapes ;; year is the year of harvest ;; -- (make-tea Size String) ;; interp: ;; size is the size of cup desired ;; type is the type of tea (as a string) ;; bo-fn : BarOrder -> ?? ;(define (bo-fn order) ; (cond ; [(coffee? order) (... ; (coffee-size order) ; (coffee-type order) ; (coffee-milk? order))] ; [(wine? order) (... ; (wine-vineyard order) ; (wine-year order))] ; [(tea? order) (... ; (tea-size order) ; (tea-type order))]))
Over the next few pages, we will give you some function definitions using structural decomposition on these data definitions. For each function definition, indicate whether the definition follows the definition.
;; function1 : Size Number Number -> Number ;; STRATEGY: structural decomposition on s (define (function1 s lo hi) (cond [(string=? s "medium") lo] [(string=? s "small") hi] [(string=? s "large") lo]))
Last modified: Mon Aug 4 22:54:37 Eastern Daylight Time 2014